#ifndef QTDBUSNODE_P_H
#define QTDBUSNODE_P_H

#include <qtdbusextrasglobal.h>

#include <QString>
#include <QObject>

#include <private/qdbusintrospection_p.h>

class QTDBUSEXTRAS_EXPORT QtDBusNode
{
    Q_DISABLE_COPY_MOVE(QtDBusNode)
public:
    struct Interface
    {
        QObject *object;
        QString name;
        QString introspection;
    };
    using InterfaceList = QList<Interface>;

    struct Location
    {
        QStringList nodes;
        const Interface *interface;
    };
    using LocationList = QList<Location>;

    explicit QtDBusNode(const QString &name = {});
    ~QtDBusNode();

    Location registerObject(QObject *object, QStringList nodes, const QString &name = {});
    QObject *unregisterObject(QStringList nodes, const QString &name);
    QObject *objectAt(const QStringList &nodes, const QString &name);

    QtDBusNode *child(const QString &name);
    QtDBusNode *addChild(const QString &name);
    QtDBusNode *child(QStringList nodes);
    void removeChild(const QString &name);

    bool empty() const;

    bool exist(const QObject *object) const;
    LocationList locationsOf(const QObject *object, QStringList depth = {}) const;
    LocationList interfaces(QStringList depth = {}) const;

    QString introspect() const;

protected:
    Interface *interface(QStringList nodes, const QString &name);
    Interface *addInterface(QObject *object, QString name);
    bool removeInterface(const QString &name);

protected:
    QString name;
    std::list<QtDBusNode> children;
    InterfaceList interfaceList;

    friend class QtDBusObjectManager;
};

#endif // QTDBUSNODE_H
